/**
* @file scene_loder.c
* @brief scene loder
* @details 
* @author huangbin
* @version V1.0.0
* @date 2025-05-7
* @copyright All documents are copyrighted by Shenzhen Xinlongwei Technology Co., LTD.
*            They may not be used for commercial purposes without permission
*/

#include "inc.h"

#include "arm_2d_scene_fan.h"
#include "arm_2d_scene_meter.h"
#include "arm_2d_scene_fitness.h"
#include "arm_2d_scene_watch.h"
#include "arm_2d_scene_knob.h"
#include "arm_2d_scene_alarm_clock.h"
#include "arm_2d_scene_bubble_charging.h"
#include "arm_2d_scene_histogram.h"
#include "arm_2d_demos.h"

static
struct {
    int8_t chIndex;
    bool bIsTimeout;
    int32_t nDelay;
    int64_t lTimeStamp;
    
} s_tDemoCTRL = {
    .chIndex = -1,
    .bIsTimeout = true,
};
//void arm_2d_scene_watch_face_0_loader(void)
//{
//    arm_2d_scene_watch_face_01_init(&DISP0_ADAPTER);//星云表盘    
//}
void arm_2d_scene_fan_loader(void)
{
    arm_2d_scene_fan_init(&DISP0_ADAPTER);//风扇旋转   
}

void arm_2d_scene_meter_loader(void)
{
    arm_2d_scene_meter_init(&DISP0_ADAPTER); //仪表盘   
}

void arm_2d_scene_balls_loader(void)
{
    arm_2d_scene_balls_init(&DISP0_ADAPTER); //balls 
}

void arm_2d_scene_text_reader_loader(void)
{
    arm_2d_scene_text_reader_init(&DISP0_ADAPTER); //text reader   
}

void arm_2d_scene_compass_loader(void)
{
    arm_2d_scene_compass_init(&DISP0_ADAPTER); //compass   
}
void arm_2d_scene_hollow_out_list_loader(void)
{
    arm_2d_scene_hollow_out_list_init(&DISP0_ADAPTER);//电梯蜂窝列表滚动  
}
void arm_2d_scene_fitness_loader(void)
{
    arm_2d_scene_fitness_init(&DISP0_ADAPTER); //圆环  
}
void arm_2d_scene_watch_loader(void)
{
    arm_2d_scene_watch_init(&DISP0_ADAPTER); //watch  
}
void arm_2d_scene_ruler_loader(void)
{
    arm_2d_scene_ruler_init(&DISP0_ADAPTER);//标尺，刻度盘 
}
void arm_2d_scene_knob_loader(void)
{
    arm_2d_scene_knob_init(&DISP0_ADAPTER); 
}
//void arm_2d_scene_matrix_loader(void)
//{
//    arm_2d_scene_matrix_init(&DISP0_ADAPTER);         //黑客帝国字符雨
//}
//void arm_2d_scene_progress_status_loader(void)
//{
//    arm_2d_scene_progress_status_init(&DISP0_ADAPTER);          //进度条
//}
//void scene_alarm_clock_loader(void) 
//{
////    arm_2d_scene_player_set_switching_mode( &DISP0_ADAPTER,
////                                            ARM_2D_SCENE_SWITCH_MODE_SLIDE_LEFT);
////    arm_2d_scene_player_set_switching_period(&DISP0_ADAPTER, 500);
//    arm_2d_scene_alarm_clock_init(&DISP0_ADAPTER);
//}
void arm_2d_scene_histogram_loader(void)
{
    arm_2d_scene_histogram_init(&DISP0_ADAPTER); 
}
void arm_2d_scene_gas_gauge_loader(void)
{
    arm_2d_scene_gas_gauge_init(&DISP0_ADAPTER); 
}

typedef struct demo_scene_t {
    int32_t nLastInMS;
    void (*fnLoader)(void);
} demo_scene_t;

static demo_scene_t const c_SceneLoaders[] = {
    {5000,arm_2d_scene_watch_loader},      
    {5000,arm_2d_scene_fan_loader},   
    {5000,arm_2d_scene_meter_loader},  
    {5000,arm_2d_scene_gas_gauge_loader}, 
    {5000,arm_2d_scene_histogram_loader},   
    {5000,arm_2d_scene_hollow_out_list_loader},      
    {5000,arm_2d_scene_fitness_loader},  
    {5000,arm_2d_scene_ruler_loader}, 
    {5000,arm_2d_scene_compass_loader}, 
    {5000,arm_2d_scene_text_reader_loader}, 
    {5000,arm_2d_scene_knob_loader},   
//    {8000,arm_2d_scene_watch_face_0_loader}, 
//    {8000,arm_2d_scene_matrix_loader}, 
//    {8000,scene_alarm_clock_loader},  
//    {5000,arm_2d_scene_progress_status_loader},  

};
/* load scene one by one */
void before_scene_switching_handler(void *pTarget,
                                    arm_2d_scene_player_t *ptPlayer,
                                    arm_2d_scene_t *ptScene)
{
   switch (arm_2d_scene_player_get_switching_status(&DISP0_ADAPTER)) {
        case ARM_2D_SCENE_SWITCH_STATUS_MANUAL_CANCEL:
            s_tDemoCTRL.chIndex--;
            break;
        default:
            s_tDemoCTRL.chIndex++;
            break;
    }

    if (s_tDemoCTRL.chIndex >= dimof(c_SceneLoaders)) {
        s_tDemoCTRL.chIndex = 0;
    } else if (s_tDemoCTRL.chIndex < 0) {
        s_tDemoCTRL.chIndex += dimof(c_SceneLoaders);
    }
    
    /* call loader */
    arm_with(const demo_scene_t, &c_SceneLoaders[s_tDemoCTRL.chIndex]) {
        if (_->nLastInMS > 0) {
            s_tDemoCTRL.bIsTimeout = false;
            s_tDemoCTRL.lTimeStamp = 0;
            s_tDemoCTRL.nDelay = _->nLastInMS;
        }
        _->fnLoader();
    }
    
}
void load_scene_timeout_check(void)
{
    if (!s_tDemoCTRL.bIsTimeout) {

    if (arm_2d_helper_is_time_out(s_tDemoCTRL.nDelay, &s_tDemoCTRL.lTimeStamp)) {
        s_tDemoCTRL.bIsTimeout = true;

        arm_2d_scene_player_switch_to_next_scene(&DISP0_ADAPTER);
    }
    }
}
//////////////////////////////File end/////////////////////////////////////

